package cs304.p3.library.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import cs304.p3.library.util.SqlUtils;

public class FineDao extends Dao {
	public void insertFine(String fid, int amount, String issuedDate, String paidDate, String borid) throws SQLException {
		List<String> values = Lists.newArrayList();
		values.add(fid);
		values.add(String.valueOf(amount));
		values.add(issuedDate);
		values.add(paidDate);
		values.add(borid);	
		String sql = SqlUtils.insertSql("Fine", values);
		PreparedStatement ps = connection.prepareStatement(sql);
		ps.executeUpdate();
	}

	public void updateFine(String fid, String paidDate) throws SQLException {
		Map<String,String> updateVals = Maps.newHashMap();
		updateVals.put("paidDate", paidDate);
		Map<String,String> whereVals = Maps.newHashMap();
		whereVals.put("fid", fid);
		String sql = SqlUtils.updateSql("Fine", updateVals, whereVals);
		PreparedStatement ps = connection.prepareStatement(sql);
		ps.executeUpdate();		
	}
	
	/*
	public List<Fine> selectFine(String fid) throws SQLException {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT * FROM Fine");
		sql.append(" WHERE ");
		Map<String,String> keyVals = Maps.newHashMap();
		keyVals.put("fid", fid);
		sql.append(SqlUtils.whereStrVal(keyVals));

		System.out.println(sql.toString());
		PreparedStatement ps = connection.prepareStatement(sql.toString());
		ResultSet rs = ps.executeQuery();
		
		List<Fine> fines = Lists.newArrayList();

		while(rs.next()) {
			Fine fine = new Fine();
			fine.setAmount(rs.getInt("amount"));
			fine.setIssuedDate(rs.getString("issueDate"));
			fine.setPaidDate(rs.getString("paidDate"));
			fines.add(fine);
		}
		
		return fines;
	}
	*/
}

